<?php
/*********************/	
add_action( 'admin_init', 'white_theme_options_init' );
add_action( 'admin_menu', 'white_theme_options_add_page' );
/*********************/	
function white_theme_options_init(){
	register_setting( 
	'white_options', 
	'white_theme_options', 
	'white_theme_options_validate' );
}
/*********************/	
function white_theme_options_add_page() {
	add_theme_page( 
	__( 'Theme Options', 'mt-white' ), 
	__( 'Theme Options', 'mt-white' ), 
	'edit_theme_options', 
	'white_theme_options', 
	'white_theme_options_do_page' );
}
/*********************/	
function white_theme_options_do_page() {
	if ( ! isset( $_REQUEST['updated'] ) )
		$_REQUEST['updated'] = false;
?>
<div class="wrap">
	<?php	screen_icon();?>
	<h2><?php	printf(__('%s Theme Options', 'mt-white'), get_current_theme());?></h2>
	<?php	settings_errors();?>

	<form method="post" action="options.php">
		<?php	settings_fields('white_options');?>
		<?php	$options = get_option('white_theme_options');?>

		<table class="form-table">
			<tr valign="top">
				<th scope="row"><?php	_e('Default Layout ', 'mt-white');?></th>
				<td class="sidebar-content">
				<input id="white_theme_options[white_sidebar-content]" name="white_theme_options[white_sidebar-content]" type="checkbox" value="1" <?php	checked(true, $options['white_sidebar-content']);?> />
				<label class="description" for="white_theme_options[white_sidebar-content]"><?php	_e('Sidebar on the left side', 'mt-white');?></label></td>
			</tr>
			<tr valign="top">
				<th scope="row"><?php	_e('Single page ', 'mt-white');?></th>
				<td class="sidebar-content">
				<input id="white_theme_options[white_content]" name="white_theme_options[white_content]" type="checkbox" value="1" <?php	checked(true, $options['white_content']);?> />
				<label class="description" for="white_theme_options[white_content]"><?php	_e('One column', 'mt-white');?></label></td>
			</tr>
			<tr valign="top">
				<th scope="row"><?php	_e('Lightbox', 'mt-white');?></th>
				<td class="sidebar-content">
				<input id="white_theme_options[white_lightbox]" name="white_theme_options[white_lightbox]" type="checkbox" value="1" <?php	checked(true, $options['white_lightbox']);?> />
				<label class="description" for="white_theme_options[white_lightbox]"><?php	_e('Turn on the "lightbox" effect to your photos (Gallery - Link thumbnails to: Image File, Image with the signature)', 'mt-white');?></label></td>
			</tr>
		</table>
		<?php submit_button();?>
	</form>
</div>
<?php
}
/*********************/
function white_theme_options_validate( $input ) {

if ( ! isset( $input['white_sidebar-content'] ) )
$input['white_sidebar-content'] = null;
$input['white_sidebar-content'] = ( $input['white_sidebar-content'] == 1 ? 1 : 0 );

if ( ! isset( $input['white_content'] ) )
$input['white_content'] = null;
$input['white_content'] = ( $input['white_content'] == 1 ? 1 : 0 );

if ( ! isset( $input['white_lightbox'] ) )
$input['white_lightbox'] = null;
$input['white_lightbox'] = ( $input['white_lightbox'] == 1 ? 1 : 0 );
return $input;
}
/*********************/
function white_pages_classes( $existing_classes ) {
$options = get_option( 'white_theme_options' );

if ($options['white_content'] <> '1' )
$classes[] = 'white_two-column';
else
if ( is_singular()) :
$classes[] = 'white_one-column';
else :
$classes[] = 'white_two-column';
endif;

if ( $options['white_sidebar-content'] <> '1' )
$classes[] = 'white_right-sidebar';
else
$classes[] = 'white_left-sidebar';

return array_merge( $existing_classes, $classes );
}
add_filter( 'body_class', 'white_pages_classes');
/*********************/
function white_fancybox_js() {
wp_enqueue_script('jquery');
wp_register_script('fancybox', get_template_directory_uri() .'/js/jquery.fancybox-1.3.4.pack.js', array('jquery'));
wp_enqueue_script('fancybox');
}
add_action('init', 'white_fancybox_js');
/*********************/
function white_fancybox() {
$options = get_option( 'white_theme_options' );
if ( $options['white_lightbox'] == '1' ):
$id= get_the_ID();
echo '<script type="text/javascript">
jQuery(document).ready(function($){
$(".gallery-icon a[href$=\'.jpg\'], .gallery-icon a[href$=\'.jpeg\'], .gallery-icon a[href$=\'.gif\'], .gallery-icon a[href$=\'.png\']").attr("rel", \'gallery_'. esc_attr($id) .'\').fancybox({\'transitionIn\' : \'none\',
\'transitionOut\' : \'none\', \'titlePosition\' 	: \'over\', \'titleFormat\'		: function(title, currentArray, currentIndex, currentOpts) {
return \'<span id="fancybox-title-over">'.__('Image','mt-white').' \' + (currentIndex + 1) + \' / \' + currentArray.length + (title.length ? \' &nbsp; \' + title : \'\') + \'</span>\';
}});
$(".wp-caption a[href$=\'.jpg\'], .wp-caption a[href$=\'.jpeg\'] .wp-caption a[href$=\'.gif\'] .wp-caption a[href$=\'.png\'] ").fancybox({\'transitionIn\' : \'elastic\',
\'transitionOut\' : \'elastic\'});
$(" #link-image ").fancybox({\'transitionIn\' : \'elastic\',
\'transitionOut\' : \'elastic\', \'titleShow\' : \'false\'});
});</script>';
endif;
}
add_action( 'wp_head', 'white_fancybox');
/*********************/
// adapted from http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/
